package lth.springboot.rabbitmq.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @description: 配置交换机、队列、绑定
 * @author:刘腾辉
 * @create:2020/10/20 14:09
 */
@Configuration
public class TopicConfig {
    /**
     * 申明交换机
     * @return
     */
    @Bean
    public TopicExchange topicExchange(){
        return new TopicExchange("springboot-topic-exchange");
    }

    /**
     * 申明队列
     * @return
     */
    @Bean("queueOne")
    public Queue topicQueueOne(){
        return new Queue("springboot-topic-queue-one", true, false, true,null);
    }

    @Bean("queueTwo")
    public Queue topicQueueTwo(){
        return new Queue("springboot-topic-queue-two", true, false, true,null);
    }

    /**
     * 队列绑定到交换机
     * @param topicExchange
     * @param queueOne
     * @return
     */
    @Bean
    public Binding bindingOne(TopicExchange topicExchange,Queue queueOne){
        return BindingBuilder.bind(queueOne).to(topicExchange).with("*.people.*");
    }

    @Bean
    public Binding bindingTwo(TopicExchange topicExchange,Queue queueTwo){
        return BindingBuilder.bind(queueTwo).to(topicExchange).with("#.people");
    }
}
